
library(tidyverse)

# set replication folder as working directory
setwd("~replication")

## load aggregated data from Danish registries
load("data_rerun_agg.rdata")

### FIGURE 10

rerun_agg %>%
  # remove 2017 as this is the last observed election and rerunning rates therefore are unobservable in our data
  filter(election_year!=2017) %>%
  # add 4 years in order to make the x-axis express when the rerunning is happening
  mutate(election_year=election_year+4) %>%
  ggplot(data=., aes(x=election_year,y=share_rerunner,color=sex)) +
  geom_line(linewidth = 1) +
  scale_color_manual("",values = c("black","grey")) +
  scale_x_continuous(breaks = seq(1993,2017,4), labels = seq(1993,2017,4)) +
  scale_y_continuous(breaks = seq(0,1,0.1), labels = seq(0,1,0.1)) +
  coord_cartesian(ylim = c(0.3,0.85)) +
  xlab("") +
  ylab("Share rerunning") +
  facet_wrap(~sample, ncol = 2) +
  theme_bw() +
  theme(legend.position = "top",
        panel.background = element_rect(fill = "white"),
        strip.background = element_rect("white"),
        strip.text = element_text(hjust=0, face = "bold"),
        panel.grid.major = element_blank(),panel.grid.minor = element_blank())

ggsave("figure10.pdf", width = 8, height = 4)
ggsave("figure10.png", width = 8, height = 4, dpi = 600)
